template <typename ReturnType, typename Argument1 = void,
          typename Argument2 = void>
class STC
{
public:
    typedef ReturnType (*Handler)(Argument1, Argument2);
    STC(Handler handler):prev_handler_(cur_handler_){
        cur_handler_ = handler;
    }
    ~STC(){
            cur_handler_ = prev_handler_;
    }
    ReturnType operator()(Argument1 a1, Argument2 a2){
            return cur_handler_(a1, a2);
    }
private:
    Handler prev_handler_;
    static Handler cur_handler_;
};
template <typename ReturnType, typename Argument1,typename Argument2 >
typename STC<ReturnType, Argument1, Argument2>::Handler
STC<ReturnType, Argument1, Argument2>::cur_handler_ = 0;

//specialize template
template <typename ReturnType, typename Argument >
class STC<ReturnType, Argument, void>
{
public:
    typedef ReturnType (*Handler)(Argument);
    STC(Handler handler):prev_handler_(cur_handler_){
        cur_handler_ = handler;
    }
    ~STC(){
            cur_handler_ = prev_handler_;
    }
    ReturnType operator()(Argument a){
        return cur_handler_(a);
    }
private:
    Handler prev_handler_;
    static Handler cur_handler_;
};
template<typename ReturnType, typename Argument>
typename STC<ReturnType, Argument, void>::Handler
STC<ReturnType, Argument, void>::cur_handler_ = 0;

//example
int foo(int a , int b)
{
    return a+b;
}
int foo2(int a)
{
    return a;
}

int main()
{
    STC<int, int, int>  stc(foo);
    STC<int, int, void> stc2(foo2);
    
}

    
